package reservations;

import database.Transcation;

import java.sql.*;

public class Reservation extends Transcation
{
	private short resvNum;
	private String custId;
	private short seatNum;
	
	
	// rno is reservation id; cID is custmer id, sNo is seatNo.
	//
	public Reservation( short resvNum,String custId, short seatNum)
	{
		this.resvNum = resvNum;  
		this.custId = custId;
		this.seatNum = seatNum;
	}
	
	
	public short getResvNum()
	{
		return resvNum;
	}
	
	public short getSeatNum()
	{
		return seatNum;
	}
	
	//public static Connection connectToDatabase(){;}
	public static void insertToDatabase(short seatNum, String custId)
	{
		  PreparedStatement state = null;
		  
		  try 
		  {
		  	String query =  "INSERT INTO reservation (custId, seatNum) VALUES(?,?)";
		    // now update the database, table customer.
		    
		    //Statement stat = connect.createStatement();
		    state = connect.prepareStatement(query);
		    
		    state.setString(1, custId);
		    state.setShort(2, seatNum);
		    state.executeUpdate( );
		    
		    state.close();// close the statement.
	    }
	    catch(SQLException ex)
	    {
		     System.out.println("SQLException:" + ex.getMessage());
		     System.out.println("SQLState: "  + ex.getSQLState());
		     System.out.println("Vendor Error: " + ex.getErrorCode());
	    }
    } 
    
}